package com.xinsoft.controller.basic;

import com.xinsoft.common.Response;
import com.xinsoft.entity.dto.SysNoticeDTO;
import com.xinsoft.entity.dto.SysNoticePageParam;
import com.xinsoft.service.SysNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/system/notice")
public class SysNoticeController {
    @Autowired
    private SysNoticeService sysNoticeService;

    /**
     * 删除消息
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/del")
    public Response<?> del(@Valid @RequestBody List<Integer> noticeReceiveRelIds) {
        sysNoticeService.del(noticeReceiveRelIds);
        return Response.succeed();
    }

    /**
     * 阅读消息
     */
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/read")
    public Response<?> read(@Valid @RequestBody List<Integer> noticeReceiveRelIds) {
        sysNoticeService.read(noticeReceiveRelIds);
        return Response.succeed();
    }

    /**
     * 分页
     */
    @PostMapping("/pageList")
    public Response<?> pageList(@Valid @RequestBody SysNoticePageParam sysNoticePageParam) {
        return Response.succeed(sysNoticeService.findPageListByParam(sysNoticePageParam));
    }

    /**
     * 未读条数
     */
    @GetMapping("/unreadCount")
    public Response<?> unreadCount() {
        return Response.succeed(sysNoticeService.unreadCount());
    }

    /**
     * 发送消息
     * @floder 系统管理/消息中心
     */
    @PostMapping("/sendNotice")
    public Response<?> sendNotice( @Valid @RequestBody SysNoticeDTO dto) {
        sysNoticeService.send(dto);
        return Response.succeed();
    }

}
